package com.ruoyi.rsikManage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.GenericMethods;
import com.ruoyi.rsikManage.domain.AlarmEvent;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rsikManage.domain.TVideoMessageQueue;
import com.ruoyi.rsikManage.service.ITVideoMessageQueueService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 视频转换消息队列Controller
 *
 * @author sxygsj
 * @date 2024-09-10
 */
@RestController
@RequestMapping("/rsikManage/queue")
public class TVideoMessageQueueController extends BaseController
{
    @Autowired
    private ITVideoMessageQueueService tVideoMessageQueueService;

    @Value("${system.videoFilePath}")
    String videoFilePath;

    @Value("${system.videoProxyFilePath}")
    String videoProxyFilePath;
    /**
     * 查询视频转换消息队列列表
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:queue:list')")
    @PostMapping("/videoConversion")
    public AjaxResult videoConversion(@RequestBody List<AlarmEvent> alarmEvents)
    {

        try{
            for (AlarmEvent data :alarmEvents){
                tVideoMessageQueueService.videoConversion(data);

            }
            return new AjaxResult(200,"开始转换请稍后查看");
        }catch (Exception e){
            return new AjaxResult(500,"转换异常");
        }


    }

    /**
     * 视频上传
     */
    @PostMapping("/videoConversion/upload")
    public AjaxResult videoConversionUpload(@RequestPart("file") MultipartFile file,
                                            @RequestParam(required = false, defaultValue = "defaultStoragePath") String storagePath)
    {
        String originalFilename = file.getOriginalFilename();
        String s = GenericMethods.uploadFile(file, videoFilePath + "\\old\\" + originalFilename);
        if (s.equals("文件上传成功")){
            return new AjaxResult(200,"文件上传成功");
        }else {
            return new AjaxResult(500,"文件上传失败");
        }
    }




    /**
     * 查询视频转换消息队列列表
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:queue:list')")
    @GetMapping("/list")
    public TableDataInfo list(TVideoMessageQueue tVideoMessageQueue)
    {
        startPage();
        List<TVideoMessageQueue> list = tVideoMessageQueueService.selectTVideoMessageQueueList(tVideoMessageQueue);
        return getDataTable(list);
    }

    /**
     * 导出视频转换消息队列列表
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:queue:export')")
    @Log(title = "视频转换消息队列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TVideoMessageQueue tVideoMessageQueue)
    {
        List<TVideoMessageQueue> list = tVideoMessageQueueService.selectTVideoMessageQueueList(tVideoMessageQueue);
        ExcelUtil<TVideoMessageQueue> util = new ExcelUtil<TVideoMessageQueue>(TVideoMessageQueue.class);
        util.exportExcel(response, list, "视频转换消息队列数据");
    }

    /**
     * 获取视频转换消息队列详细信息
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:queue:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tVideoMessageQueueService.selectTVideoMessageQueueById(id));
    }

    /**
     * 新增视频转换消息队列
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:queue:add')")
    @Log(title = "视频转换消息队列", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TVideoMessageQueue tVideoMessageQueue)
    {
        return toAjax(tVideoMessageQueueService.insertTVideoMessageQueue(tVideoMessageQueue));
    }

    /**
     * 修改视频转换消息队列
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:queue:edit')")
    @Log(title = "视频转换消息队列", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TVideoMessageQueue tVideoMessageQueue)
    {
        return toAjax(tVideoMessageQueueService.updateTVideoMessageQueue(tVideoMessageQueue));
    }

    /**
     * 删除视频转换消息队列
     */
    //@PreAuthorize("@ss.hasPermi('rsikManage:queue:remove')")
    @Log(title = "视频转换消息队列", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tVideoMessageQueueService.deleteTVideoMessageQueueByIds(ids));
    }
}
